#!/bin/bash

# 一键打包脚本 - 构建前端 + 打包部署文件

echo "=========================================="
echo "  文件同步器 - 一键打包"
echo "=========================================="
echo ""

# 检查脚本是否可执行
if [ ! -x "./build-frontend.sh" ]; then
    chmod +x build-frontend.sh
fi

if [ ! -x "./package-for-deployment.sh" ]; then
    chmod +x package-for-deployment.sh
fi

# 第一步：构建前端
echo "🔨 步骤 1/2: 构建前端..."
echo ""
./build-frontend.sh

if [ $? -ne 0 ]; then
    echo ""
    echo "❌ 前端构建失败，停止打包"
    exit 1
fi

echo ""
echo "=========================================="
echo ""

# 第二步：打包部署文件
echo "📦 步骤 2/2: 打包部署文件..."
echo ""
./package-for-deployment.sh

if [ $? -ne 0 ]; then
    echo ""
    echo "❌ 打包失败"
    exit 1
fi

echo ""
echo "=========================================="
echo "🎉 一键打包完成！"
echo "=========================================="
echo ""
echo "📦 部署包已生成，可以上传到服务器了"
echo ""
echo "📖 部署说明:"
echo "   1. 将生成的 .tar.gz 文件上传到服务器"
echo "   2. 按照 '宝塔面板部署教程.md' 进行部署"
echo ""
echo "💡 快速部署命令:"
echo "   scp file-sync-server_*.tar.gz root@your-server:/www/wwwroot/"
echo ""
